package com.jingsong.studentapp.page;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.jingsong.studentapp.R;
import com.jingsong.studentapp.adapter.MainAdapter;
import com.jingsong.studentapp.lister.OnItemEventListener;
import com.jingsong.studentapp.lister.OnSubIndexEventListener;
import com.jingsong.studentapp.model.LessonModel;
import com.jingsong.studentapp.model.WorkModel;

import java.util.ArrayList;

/**
 * 作业
 */
public class MainActivity extends AppCompatActivity implements OnSubIndexEventListener {
    private MainAdapter<WorkModel> mainAdapter;
    private ArrayList<WorkModel> allDatas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tvTitle = findViewById(R.id.tvName);
        tvTitle.setText("作业");


        RecyclerView rcvList = findViewById(R.id.rcvList);
        rcvList.setLayoutManager(new LinearLayoutManager(this));
        mainAdapter = new MainAdapter<>(this);
        mainAdapter.setEventListener(this);
        rcvList.setAdapter(mainAdapter);


        allDatas = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            WorkModel workModel = new WorkModel();
            workModel.name = "课程 " + i;
            workModel.lastTime = "2022-01-10 12:00";
            workModel.status = i % 3 + 1;
            workModel.lessonModels = new ArrayList<>();
            for (int j = 0; j < 5; j++) {
                LessonModel lessonModel = new LessonModel();
                lessonModel.lessonName = "习题 " + j;
                lessonModel.lessonStatus = j % 3 + 1;
                lessonModel.examStatus = j % 2 + 1;
                workModel.lessonModels.add(lessonModel);
            }
            allDatas.add(workModel);
        }

        mainAdapter.setDatas(allDatas);
    }


    @Override
    public void onItemEvent(int parent, int subIndex) {
        startActivity(new Intent(MainActivity.this, LessonInfoActivity.class));
    }
}